package lc;

import java.util.Arrays;

public class lc2171 {
    public static void main(String[] args) {
        minimumRemoval(new int[]{2,10,3,2});
    }
    public static long minimumRemoval(int[] beans) {
        //不对，应该是找任意的从排序变零，剩下的变成和留下的值一样，感觉是n2
        if(beans.length == 1) return 0;
        Arrays.sort(beans);
        long res = 0;
        long cur;

        for(int i = 0; i < beans.length; ++i){
            res += beans[i];
        }
        long sum = res;
        res = sum - beans.length  * beans[0];
        for(int i = 0; i < beans.length - 1; ++i){
            cur = sum - (beans.length - i - 1) * beans[i + 1];
            res = Math.min(cur, res);
        }
        return res;
    }
}
